// ml:run = time -p $bin < input
#include <cstdio>
#include <cstring>

template <class T>
void scan(T & a)
{
	a = 0;
	bool flag = false;
	char ch = std::getchar();
	if (ch == '-')
		flag = true;
	else if (ch >= '0' && ch <= '9')
		a = ch - '0';

	while ((ch = std::getchar()) >= '0' && ch <= '9')
		a = a * 10 + ch - '0';
	if (flag) a = -a;
}

int const maxn = 3000007;
int sum[maxn * 4];
int ans[maxn];
int n, k, q, round;

void push_up(int id)
{
    sum[id] = sum[id * 2] + sum[id * 2 + 1];
}

void remove(int id, int l, int r, int kth)
{
    if (l == r) {
        sum[id] = 0;
        ans[round++] = l;
        return;
    }
    int mid = (l + r) / 2;
    if (sum[id * 2] < kth) {
        kth -= sum[id * 2];
        remove(id * 2 + 1, mid + 1, r, kth);
    } else {
        remove(id * 2, l, mid, kth);
    }
    push_up(id);
}

void build(int id, int l, int r)
{
    if (l == r) {
        sum[id] = 1;
        return;
    }
    int mid = (l + r) / 2;
    build(id * 2, l, mid);
    build(id * 2 + 1, mid + 1, r);
    push_up(id);
}

void init()
{
    round = 1;
    for (int i = 0; i <= 4 * n; i++) sum[i] = 0;
    memset(sum, 0, sizeof(sum));
    build(1, 1, n);
}

int main()
{
    int T; scan(T);
    while (T--) {
        scan(n); scan(k); scan(q);
        init();
        for (int tn = n; tn; ) {
            for (int tk = 1, i = 0; tk - i <= tn; tk += k, tn--, i++)
                remove(1, 1, n, tk - i);
        }
//        for (int i = 1; i <= n; i++) std::cout << ans[i] << " "; std::cout << "\n";
        for (int i = 0, x; i < q; i++) {
            scan(x);
            printf("%d ", ans[x]);
        }
        printf("\n");
    }
}

